home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / vbcc / parse_expr.c < prev    next >
C/C++ Source or Header  |  1995-11-18  |  22KB  |  745 lines

  1. #include "vbc.h"
  2.  
  3. np expression(void)
  4. /*  Komma-Ausdruecke                                        */
  5. {
  6.     np left,right,new;
  7.     left=assignment_expression();
  8.     if(!left->flags) return(0);
  9.     killsp();
  10.     while(*s==','){
  11.         s++;
  12.         killsp();
  13.         right=assignment_expression();
  14.         new=(np)mymalloc(NODES);
  15.         new->left=left;
  16.         new->right=right;
  17.         new->ntyp=0;
  18.         new->flags=KOMMA;
  19.         left=new;
  20.         killsp();
  21.     }
  22.     return(left);
  23. }
  24. np assignment_expression(void)
  25. /*  Zuweisungsausdruecke                                    */
  26. {
  27.     np left,new;int c=0;
  28.     left=conditional_expression();
  29.     killsp();
  30.     if(*s!='='&&*(s+1)!='='&&*(s+2)!='=') return(left);
  31.     if(*s=='=') {c=ASSIGN;s++;} else
  32.     {if(*s=='*'&&*(s+1)=='=') {c=ASSIGNMULT;s+=2;}  else
  33.     {if(*s=='/'&&*(s+1)=='=') {c=ASSIGNDIV;s+=2;}   else
  34.     {if(*s=='%'&&*(s+1)=='=') {c=ASSIGNMOD;s+=2;}   else
  35.     {if(*s=='+'&&*(s+1)=='=') {c=ASSIGNADD;s+=2;}   else
  36.     {if(*s=='-'&&*(s+1)=='=') {c=ASSIGNSUB;s+=2;}   else
  37.     {if(*s=='&'&&*(s+1)=='=') {c=ASSIGNAND;s+=2;}   else
  38.     {if(*s=='^'&&*(s+1)=='=') {c=ASSIGNXOR;s+=2;}   else
  39.     {if(*s=='|'&&*(s+1)=='=') {c=ASSIGNOR;s+=2;}    else
  40.     {if(*s=='<'&&*(s+1)=='<') {c=ASSIGNLSHIFT;s+=3;}else
  41.     {if(*s=='>'&&*(s+1)=='>') {c=ASSIGNRSHIFT;s+=3;}else {return(left);}
  42.     }}}}}}}}}}
  43.     new=(np)mymalloc(NODES);
  44.     new->left=left;
  45.     new->ntyp=0;
  46.     if(c==ASSIGN){
  47.         new->right=assignment_expression();
  48.         new->flags=ASSIGN;
  49.     }else{
  50.         /*  ASSIGNOP(a,b)->ASSIGN(a,OP(a,b))    */
  51.         new->flags=ASSIGNADD;   /* nur zum Merken, dass nur einmal  */
  52.                                 /* ausgewertet werden darf          */
  53.         new->right=(np)mymalloc(NODES);
  54.         new->right->left=left;
  55.         new->right->right=assignment_expression();
  56.         new->right->ntyp=0;
  57.         if(c==ASSIGNMULT) new->right->flags=MULT;
  58.         if(c==ASSIGNDIV) new->right->flags=DIV;
  59.         if(c==ASSIGNMOD) new->right->flags=MOD;
  60.         if(c==ASSIGNADD) new->right->flags=ADD;
  61.         if(c==ASSIGNSUB) new->right->flags=SUB;
  62.         if(c==ASSIGNAND) new->right->flags=AND;
  63.         if(c==ASSIGNXOR) new->right->flags=XOR;
  64.         if(c==ASSIGNOR) new->right->flags=OR;
  65.         if(c==ASSIGNLSHIFT) new->right->flags=LSHIFT;
  66.         if(c==ASSIGNRSHIFT) new->right->flags=RSHIFT;
  67.     }
  68.     return(new);
  69. }
  70. np conditional_expression(void)
  71. /*  Erledigt ? :  momentan noch nicht implementiert         */
  72. {
  73.     np left,new;
  74.     left=logical_or_expression();
  75.     killsp();
  76.     if(*s=='?'){    /*  hier ein while  ?   */
  77.         s++;killsp();
  78.         new=(np)mymalloc(NODES);
  79.         new->flags=COND;
  80.         new->ntyp=0;
  81.         new->left=left;
  82.         new->right=(np)mymalloc(NODES);
  83.         new->right->flags=COLON;
  84.         new->right->ntyp=0;
  85.         new->right->left=expression();
  86.         killsp();
  87.         if(*s==':'){s++;killsp();} else error(70);
  88.         new->right->right=conditional_expression();
  89.         left=new;
  90.         killsp();
  91.     }
  92.     return(left);
  93. }
  94. np logical_or_expression(void)
  95. /*  Erledigt ||                                             */
  96. {
  97.     np left,right,new;
  98.     left=logical_and_expression();
  99.     killsp();
  100.     while(*s=='|'&&*(s+1)=='|'){
  101.         s+=2;
  102.         killsp();
  103.         right=logical_and_expression();
  104.         new=(np)mymalloc(NODES);
  105.         new->left=left;
  106.         new->right=right;
  107.         new->flags=LOR;
  108.         new->ntyp=0;
  109.         left=new;
  110.         killsp();
  111.     }
  112.     return(left);
  113. }
  114. np logical_and_expression(void)
  115. /*  Erledigt &&                                             */
  116. {
  117.     np left,right,new;
  118.     left=inclusive_or_expression();
  119.     killsp();
  120.     while(*s=='&'&&*(s+1)=='&'){
  121.         s+=2;
  122.         killsp();
  123.         right=inclusive_or_expression();
  124.         new=(np)mymalloc(NODES);
  125.         new->left=left;
  126.         new->right=right;
  127.         new->flags=LAND;
  128.         new->ntyp=0;
  129.         left=new;
  130.         killsp();
  131.     }
  132.     return(left);
  133. }
  134. np inclusive_or_expression(void)
  135. /*  Erledigt |                                              */
  136. {
  137.     np left,right,new;
  138.     left=exclusive_or_expression();
  139.     killsp();
  140.     while(*s=='|'&&*(s+1)!='|'&&*(s+1)!='='){
  141.         s++;
  142.         killsp();
  143.         right=exclusive_or_expression();
  144.         new=(np)mymalloc(NODES);
  145.         new->left=left;
  146.         new->right=right;
  147.         new->flags=OR;
  148.         new->ntyp=0;
  149.         left=new;
  150.         killsp();
  151.     }
  152.     return(left);
  153. }
  154. np exclusive_or_expression(void)
  155. /*  Erledigt ^                                              */
  156. {
  157.     np left,right,new;
  158.     left=and_expression();
  159.     killsp();
  160.     while(*s=='^'&&*(s+1)!='='){
  161.         s++;
  162.         killsp();
  163.         right=and_expression();
  164.         new=(np)mymalloc(NODES);
  165.         new->left=left;
  166.         new->right=right;
  167.         new->flags=XOR;
  168.         new->ntyp=0;
  169.         left=new;
  170.         killsp();
  171.     }
  172.     return(left);
  173. }
  174. np and_expression(void)
  175. /*  Erledigt &                                              */
  176. {
  177.     np left,right,new;
  178.     left=equality_expression();
  179.     killsp();
  180.     while(*s=='&'&&*(s+1)!='&'&&*(s+1)!='='){
  181.         s++;
  182.         killsp();
  183.         right=equality_expression();
  184.         new=(np)mymalloc(NODES);
  185.         new->left=left;
  186.         new->right=right;
  187.         new->flags=AND;
  188.         new->ntyp=0;
  189.         left=new;
  190.         killsp();
  191.     }
  192.     return(left);
  193. }
  194. np equality_expression(void)
  195. /*  Erledigt == und !=                                      */
  196. {
  197.     np left,right,new;int c;
  198.     left=relational_expression();
  199.     killsp();
  200.     while((*s=='='||*s=='!')&&*(s+1)=='='){
  201.         if(*s=='!') c=INEQUAL; else c=EQUAL;
  202.         s+=2;
  203.         killsp();
  204.         right=relational_expression();
  205.         new=(np)mymalloc(NODES);
  206.         new->left=left;
  207.         new->right=right;
  208.         new->flags=c;
  209.         new->ntyp=0;
  210.         left=new;
  211.         killsp();
  212.     }
  213.     return(left);
  214. }
  215. np relational_expression(void)
  216. /*  Erledigt <,>,<=,>=                                      */
  217. {
  218.     np left,right,new;int c;
  219.     left=shift_expression();
  220.     killsp();
  221.     while((*s=='<'&&*(s+1)!='<')||(*s=='>'&&*(s+1)!='>')){
  222.         if(*s++=='<'){
  223.             if(*s=='='){s++;c=LESSEQ;}else c=LESS;
  224.         }else{
  225.             if(*s=='='){s++;c=GREATEREQ;}else c=GREATER;
  226.         }
  227.         killsp();
  228.         right=shift_expression();
  229.         new=(np)mymalloc(NODES);
  230.         new->left=left;
  231.         new->right=right;
  232.         new->flags=c;
  233.         new->ntyp=0;
  234.         left=new;
  235.         killsp();
  236.     }
  237.     return(left);
  238. }
  239. np shift_expression(void)
  240. /*  Erledigt <<,>>                                          */
  241. {
  242.     np left,right,new;int c;
  243.     left=additive_expression();
  244.     killsp();
  245.     while((*s=='<'&&*(s+1)=='<'&&*(s+2)!='=')||(*s=='>'&&*(s+1)=='>'&&*(s+2)!='=')){
  246.         if(*s=='<') c=LSHIFT; else c=RSHIFT;
  247.         s+=2;
  248.         killsp();
  249.         right=additive_expression();
  250.         new=(np)mymalloc(NODES);
  251.         new->left=left;
  252.         new->right=right;
  253.         new->flags=c;
  254.         new->ntyp=0;
  255.         left=new;
  256.         killsp();
  257.     }
  258.     return(left);
  259. }
  260. np additive_expression(void)
  261. /*  Erledigt +,-                                            */
  262. {
  263.     np left,right,new;int c;
  264.     left=multiplicative_expression();
  265.     killsp();
  266.     while((*s=='+'||*s=='-')&&*(s+1)!='='){
  267.         if(*s++=='+') c=ADD; else c=SUB;
  268.         killsp();
  269.         right=multiplicative_expression();
  270.         new=(np)mymalloc(NODES);
  271.         new->left=left;
  272.         new->right=right;
  273.         new->flags=c;
  274.         new->ntyp=0;
  275.         left=new;
  276.         killsp();
  277.     }
  278.     return(left);
  279. }
  280. np multiplicative_expression(void)
  281. /*  Erledigt *,/,%                                          */
  282. {
  283.     np left,right,new;int c;
  284.     left=cast_expression();
  285.     killsp();
  286.     while((*s=='*'||*s=='/'||*s=='%')&&*(s+1)!='='){
  287.         if(*s=='*') c=MULT; else {if(*s=='/') c=DIV; else c=MOD;}
  288.         s++;
  289.         killsp();
  290.         right=cast_expression();
  291.         new=(np)mymalloc(NODES);
  292.         new->left=left;
  293.         new->right=right;
  294.         new->flags=c;
  295.         new->ntyp=0;
  296.         left=new;
  297.         killsp();
  298.     }
  299.     return(left);
  300. }
  301. np cast_expression(void)
  302. /*  Erledigt (typ)                                          */
  303. {
  304.     np new;char *imerk,buff[MAXI];
  305.     killsp();
  306.     if(*s!='('||!declaration(1)) return(unary_expression());
  307.     s++;killsp();
  308.     new=(np)mymalloc(NODES);
  309.     new->flags=CAST;
  310.     new->right=0;
  311.     imerk=ident;ident=buff;
  312.     new->ntyp=declarator(declaration_specifiers());
  313.     ident=imerk;
  314.     killsp();
  315.     if(*s!=')') error(59); else s++;
  316.     new->left=cast_expression();
  317.     return(new);
  318. }
  319. np unary_expression(void)
  320. /*  Erledigt !,~,++,--,+,-,*,&,sizeof                       */
  321. {
  322.     np new;char *merk=s,buff[MAXI];int done=0;
  323.     killsp();
  324.     if((*s!='s'&&*s!='+'&&*s!='-'&&*s!='&'&&*s!='*'&&*s!='~'&&*s!='!')||*(s+1)=='=') return(postfix_expression());
  325.     if(*s=='s'){
  326.         merk=s;cpbez(buff);s=merk;
  327.         if(strcmp("sizeof",buff)) return(postfix_expression());
  328.         else{
  329.             s+=6;killsp();
  330.             new=(np)mymalloc(NODES);
  331.             new->flags=CEXPR;
  332.             new->ntyp=(struct Typ *)mymalloc(TYPS);
  333.             new->ntyp->flags=UNSIGNED|LONG;
  334.             new->ntyp->next=0;
  335.             new->right=0;
  336.             new->left=0;
  337.             if(*s=='('&&declaration(1)){
  338.                 struct Typ *t;
  339.                 s++;killsp();
  340.                 merk=ident;ident=buff;
  341.                 t=declarator(declaration_specifiers());
  342.                 ident=merk;
  343.                 new->val.vulong=zl2zul(l2zl((long)szof(t)));
  344.                 freetyp(t);
  345.                 killsp();
  346.                 if(*s!=')') error(59); else s++;
  347.             }else{
  348.                 np tree;
  349.                 killsp();
  350.                 tree=unary_expression();
  351.                 if(!tree||!type_expression(tree)){
  352.                     new->val.vulong=zl2zul(l2zl(0L));
  353.                     error(73);
  354.                 }else{
  355.                     new->val.vulong=zl2zul(l2zl((long)szof(tree->ntyp)));
  356.                 }
  357.                 if(tree) free_expression(tree);killsp();
  358.             }
  359.             return(new);
  360.         }
  361.     }
  362.     new=(np)mymalloc(NODES);
  363.     new->right=0;
  364.     new->ntyp=0;
  365.     if(*s=='+'&&!done)
  366.         if(*(s+1)=='+'){
  367.             s+=2;done=1;
  368.             new->left=unary_expression();
  369.             new->flags=PREINC;
  370.         }else{
  371.             s++;free(new);
  372.             return(cast_expression());
  373.         }
  374.     if(*s=='-'&&!done){
  375.         done=1;
  376.         if(*(s+1)=='-'){
  377.             s+=2;
  378.             new->left=unary_expression();
  379.             new->flags=PREDEC;
  380.         }else{
  381.             s++;
  382.             new->left=cast_expression();
  383.             new->flags=MINUS;
  384.         }
  385.     }
  386.     if(*s=='&'&&!done){
  387.         s++;done=1;
  388.         new->left=cast_expression();
  389.         new->flags=ADDRESS;
  390.     }
  391.     if(*s=='*'&&!done){
  392.         s++;done=1;
  393.         new->left=cast_expression();
  394.         new->flags=CONTENT;
  395.     }
  396.     if(*s=='~'&&!done){
  397.         s++;done=1;
  398.         new->left=cast_expression();
  399.         new->flags=KOMPLEMENT;
  400.     }
  401.     if(*s=='!'&&!done){
  402.         s++;done=1;
  403.         new->left=cast_expression();
  404.         new->flags=NEGATION;
  405.     }
  406.     new->right=0;
  407.     new->ntyp=0;
  408.     return(new);
  409. }
  410. np postfix_expression(void)
  411. /*  Erledigt [],(),.,->,++,--                                   */
  412. {
  413.     np new,left;int done;
  414.     left=primary_expression();
  415.     killsp();
  416.     while(*s=='['||*s=='('||*s=='.'||(*s=='-'&&((*(s+1)=='-')||(*(s+1)=='>')))
  417.           ||(*s=='+'&&*(s+1)=='+')){
  418.         done=0;
  419.         new=(np)mymalloc(NODES);
  420.         new->ntyp=0;
  421.         new->right=0;
  422.         new->left=left;
  423.         if(*s=='-'){
  424.             s++;done=1;
  425.             if(*s=='-'){
  426.                 s++;
  427.                 new->flags=POSTDEC;
  428.             }else{
  429.                 s++; killsp();
  430.                 new->flags=DSTRUCT;
  431.                 new->right=identifier_expression();
  432.                 new->right->flags=MEMBER;
  433.                 new->left=(np)mymalloc(NODES);
  434.                 new->left->ntyp=0;
  435.                 new->left->left=left;
  436.                 new->left->right=0;
  437.                 new->left->flags=CONTENT;
  438.             }
  439.         }
  440.         if(*s=='['&&!done){
  441.             s++; killsp();done=1;
  442.             new->flags=CONTENT;
  443.             new->left=(np)mymalloc(NODES);
  444.             new->left->flags=ADD;
  445.             new->left->ntyp=0;
  446.             new->left->left=left;
  447.             new->left->right=expression();
  448.             killsp();
  449.             if(*s!=']') error(62); else s++;
  450.         }
  451.         if(*s=='+'&&!done){
  452.             s+=2;done=1;
  453.             new->flags=POSTINC;
  454.         }
  455.         if(*s=='.'&&!done){
  456.             s++;killsp();done=1;
  457.             new->right=identifier_expression();
  458.             new->flags=DSTRUCT;
  459.             new->right->flags=MEMBER;
  460.         }
  461.         if(*s=='('&&!done){
  462.             struct argument_list *al,*first_alist=0,*last_alist=0;np n;
  463.             s++;killsp();done=1;
  464.             new->flags=CALL;
  465.             new->right=0;
  466.             while(*s!=')'){
  467.                 n=assignment_expression();
  468.                 al=(struct argument_list *)mymalloc(sizeof(struct argument_list));
  469.                 al->arg=n;al->next=0;
  470.                 if(last_alist){
  471.                     last_alist->next=al;
  472.                     last_alist=al;
  473.                 }else{
  474.                     last_alist=first_alist=al;
  475.                 }
  476.                 killsp();
  477.                 if(*s==',') {s++;killsp();} /* hier noch strenger */
  478.             }
  479.             new->alist=first_alist;
  480.             if(*s!=')') error(59); else s++;
  481.         }
  482.         left=new;
  483.         killsp();
  484.     }
  485.     return(left);
  486. }
  487. np primary_expression(void)
  488. /*  Hier fehlt noch allerhand                               */
  489. {
  490.     np new;
  491.     if((*s>='0'&&*s<='9')||*s=='.') return(constant_expression());
  492.     if(*s=='\"'||*s=='\''||(*s=='L'&&(*(s+1)=='\''||*(s+1)=='\"'))) return(string_expression());
  493.     if(*s=='('){
  494.         s++;killsp();
  495.         new=expression();
  496.         killsp();
  497.         if(*s!=')') error(59); else s++;
  498.         return(new);
  499.     }
  500.     return(identifier_expression());
  501. }
  502. np string_expression(void)
  503. /*  Gibt Zeiger auf string oder Zeichenkonstante zurueck    */
  504. {
  505.     np new; char f,string[MAXINPUT],*p;int flag,val;zlong zl;
  506.     if(*s=='L') s++;    /*  Noch keine erweiterten Zeichen  */
  507.     p=string;f=*s++;
  508.     while(1){
  509.         while(*s!=f&&p<&string[MAXINPUT-1]){
  510.             if(*s=='\\'){
  511.                 s++;
  512.                 if(*s=='\\'){*p++='\\';s++;continue;}
  513.                 if(*s=='n'){*p++='\n';s++;continue;}
  514.                 if(*s=='t'){*p++='\t';s++;continue;}
  515.                 if(*s=='r'){*p++='\r';s++;continue;}
  516.                 if(*s=='v'){*p++='\v';s++;continue;}
  517.                 if(*s=='b'){*p++='\b';s++;continue;}
  518.                 if(*s=='f'){*p++='\f';s++;continue;}
  519.                 if(*s=='a'){*p++='\a';s++;continue;}
  520.                 if(*s=='\?'){*p++='\?';s++;continue;}
  521.                 if(*s=='\''){*p++='\'';s++;continue;}
  522.                 if(*s=='\"'){*p++='\"';s++;continue;}
  523.                 flag=val=0;
  524.                 while(*s>='0'&&*s<='7'&&flag<3){
  525.                     val=val*8+*s-'0';
  526.                     s++;flag++;
  527.                 }
  528.                 if(flag){*p++=val;continue;}
  529.                 if(*s=='x'){
  530.                     s++;val=0;
  531.                     while((*s>='0'&&*s<='9')||(*s>='a'&&*s<='f')||(*s>='A'&&*s<='F')){
  532.                         val=val*16;
  533.                         if(*s>='0'&&*s<='9') val+=*s-'0';
  534.                         if(*s>='a'&&*s<='f') val+=*s-'a'+10;
  535.                         if(*s>='A'&&*s<='F') val+=*s-'A'+10;
  536.                         s++;
  537.                     }
  538.                     *p++=val;continue;
  539.                 }
  540.                 error(71);
  541.             }
  542.             *p++=*s++;
  543.         }
  544.         if(*s!=f) error(74); else s++;
  545.         killsp();
  546.         if(f!='\"'||*s!=f) break; else s++;
  547.     }
  548.     *p=0;
  549.     new=(np)mymalloc(NODES);
  550.     new->ntyp=(struct Typ *)mymalloc(TYPS);
  551.     if(f=='\"'){
  552.         struct const_list *cl,**prev;int i;
  553.         new->ntyp->flags=ARRAY;
  554.         new->ntyp->size=p-string+1;
  555.         new->ntyp->next=(struct Typ *)mymalloc(TYPS);
  556.         new->ntyp->next->flags=CHAR;
  557.         new->ntyp->next->next=0;
  558.         new->flags=STRING;
  559.         prev=(struct const_list **)&new->identifier;
  560.         for(i=0;i<p-string+1;i++){
  561.             cl=(struct const_list *)mymalloc(CLS);
  562.             cl->next=0;
  563.             cl->tree=0;
  564.             cl->other=(struct const_list *)mymalloc(CLS);
  565.             cl->other->next=cl->other->other=0;
  566.             cl->other->tree=0;
  567.             cl->other->val.vchar=zl2zc(l2zl((long)string[i]));
  568.             *prev=cl;
  569.             prev=&cl->next;
  570.         }
  571. /*        new->identifier=add_identifier(string,p-string);*/
  572.         new->val.vlong=l2zl(0L);
  573.     }else{
  574.         new->ntyp->flags=CONST|INT;
  575.         new->ntyp->next=0;
  576.         new->flags=CEXPR;
  577.         zl=l2zl(0L);
  578.         p--;
  579.         if(p>string) error(72);
  580.         while(p>=string){
  581.             /*  zl=zl<<CHAR_BIT+*p  */
  582.             zl=zllshift(zl,l2zl((long)CHAR_BIT));
  583.             zl=zladd(zl,l2zl((long)*p));
  584.             new->val.vint=zl2zi(zl);
  585.             p--;
  586.         }
  587.     }
  588.     new->left=new->right=0;
  589.     return(new);
  590. }
  591. np constant_expression(void)
  592. /*  Gibt Zeiger auf erzeugt Struktur fuer Konstante zurueck */
  593. /*  Es werden die Werte aus <limits.h> benutzt.             */
  594. {
  595.     np new; zdouble db;
  596.     zulong value,zbase,digit;unsigned long base=10,t;char *merk;
  597.     merk=s;
  598.     value=ul2zul(0L);
  599.     new=(np)mymalloc(NODES);
  600.     new->ntyp=(struct Typ *)mymalloc(TYPS);
  601.     new->ntyp->flags=0;
  602.     new->ntyp->next=0;
  603.     new->flags=CEXPR;
  604.     new->left=new->right=0;
  605.     new->sidefx=0;
  606.     if(*s=='0'){
  607.         s++;
  608.         if(*s=='x'||*s=='X'){s++;base=16;} else base=8;
  609.     }
  610.     zbase=ul2zul(base);
  611.     if(*s>='0'&&*s<='9') t=*s-'0'; else{
  612.     if(*s>='a'&&*s<='f') t=*s-'a'+10; else{
  613.     if(*s>='A'&&*s<='F') t=*s-'A'+10; else{t=20;}}}
  614.     while(t<base){
  615.         digit=ul2zul(t);
  616.         value=zuladd(zulmult(value,zbase),digit);
  617.         s++;
  618.         if(*s>='0'&&*s<='9') t=*s-'0'; else{
  619.         if(*s>='a'&&*s<='f') t=*s-'a'+10; else{
  620.         if(*s>='A'&&*s<='F') t=*s-'A'+10; else{t=20;}}}
  621.     }
  622.     while(*s=='u'||*s=='U'||*s=='l'||*s=='L'){
  623.         if(*s=='u'||*s=='U'){
  624.             if(zulleq(value,UINT_MAX)) new->ntyp->flags=UNSIGNED|INT;
  625.              else               new->ntyp->flags=UNSIGNED|LONG;
  626.         }else{
  627.             if(zulleq(value,LONG_MAX)) new->ntyp->flags=LONG;
  628.              else               new->ntyp->flags=UNSIGNED|LONG;
  629.         }
  630.         s++;
  631.     }
  632.     if(new->ntyp->flags==0){
  633.         if(base==10){
  634.             if(zulleq(value,INT_MAX)) new->ntyp->flags=INT; else{
  635.             if(zulleq(value,LONG_MAX)) new->ntyp->flags=LONG; else
  636.                                 new->ntyp->flags=UNSIGNED|LONG;}
  637.         }else{
  638.             if(zulleq(value,INT_MAX)) new->ntyp->flags=INT; else{
  639.             if(zulleq(value,UINT_MAX))new->ntyp->flags=UNSIGNED|INT; else{
  640.             if(zulleq(value,LONG_MAX))new->ntyp->flags=LONG; else
  641.                                new->ntyp->flags=UNSIGNED|LONG;}}
  642.         }
  643.     }
  644.     if(*s=='.'||*s=='e'||*s=='E'){
  645.     /*  Fliesskommakonstante, ignoriert vorher berechneten Wert, falls er   */
  646.     /*  nicht dezimal und nicht 0 war (da er dann oktal war)                */
  647.         if(*merk=='0'&&!zuleq(value)){
  648.             value=ul2zul(0UL);zbase=ul2zul(10UL);
  649.             while(*merk>='0'&&*merk<='9'){
  650.                 digit=ul2zul((unsigned long)(*merk-'0'));
  651.                 value=zuladd(zulmult(value,zbase),digit);
  652.                 merk++;
  653.             }
  654.             if(merk!=s) error(75);
  655.         }
  656.         db=zul2zd(value);
  657.         if(*s=='.'){
  658.         /*  Teil hinter Kommastellen    */
  659.             zdouble zquot,zbased,digit;
  660.             s++;
  661.             zbased=d2zd(10);zquot=d2zd(0.1);
  662.             while(*s>='0'&&*s<='9'){
  663.                 digit=d2zd((double)(*s-'0'));
  664.                 db=zdadd(db,zdmult(digit,zquot));
  665.                 zquot=zddiv(zquot,zbased);
  666.                 s++;
  667.             }
  668.  
  669.         }
  670.         if(*s=='e'||*s=='E'){
  671.         /*  Exponentialdarstellung  */
  672.             int exp,vorz,i;zdouble zbased;
  673.             zbased=d2zd((double)10);
  674.             s++;
  675.             if(*s=='-'){
  676.                 s++;vorz=-1;
  677.             }else{
  678.                 vorz=1;if(*s=='+') s++;
  679.             }
  680.             exp=0;
  681.             while(*s>='0'&&*s<='9') exp=exp*10+*s++-'0';
  682.             for(i=0;i<exp;i++){
  683.                 if(vorz>0) db=zdmult(db,zbased);
  684.                     else   db=zddiv(db,zbased);
  685.             }
  686.         }
  687.         new->ntyp->flags=DOUBLE;
  688.         if(*s=='f'||*s=='F'){
  689.             new->ntyp->flags=FLOAT;s++;
  690.         }else{
  691.         /*  long double werden nicht unterstuetzt und sind==double :-(  */
  692.             if(*s=='l'||*s=='L') s++;
  693.         }
  694.     }
  695.     if(new->ntyp->flags==FLOAT) new->val.vfloat=zd2zf(db);
  696.     if(new->ntyp->flags==DOUBLE) new->val.vdouble=db;
  697.     if(new->ntyp->flags==INT) new->val.vint=zl2zi(zul2zl(value));
  698.     if(new->ntyp->flags==(UNSIGNED|INT)) new->val.vuint=zul2zui(value);
  699.     if(new->ntyp->flags==LONG) new->val.vlong=zul2zl(value);
  700.     if(new->ntyp->flags==(UNSIGNED|LONG)) new->val.vulong=value;
  701.     return(new);
  702. }
  703. np identifier_expression(void)
  704. /*  Erzeugt Identifier mit Knoten                           */
  705. {
  706.     np new;char buff[MAXI];
  707.     killsp();cpbez(buff);
  708.     new=(np)mymalloc(NODES);
  709.     new->flags=IDENTIFIER;
  710.     new->left=new->right=0;
  711.     new->identifier=add_identifier(buff,strlen(buff));
  712.     new->ntyp=0;
  713.     new->sidefx=0;
  714.     new->val.vlong=l2zl(0L);
  715.     if(new->identifier==empty) {error(76);new->flags=0;}
  716.     return(new);
  717. }
  718. void free_alist(struct argument_list *p)
  719. /*  Gibt argument_list inkl. expressions frei                   */
  720. {
  721.     struct argument_list *merk;
  722.     while(p){
  723.         merk=p->next;
  724.         if(p->arg) free_expression(p->arg);
  725.         free(p);
  726.         p=merk;
  727.     }
  728. }
  729. void free_expression(np p)
  730. /*  Gibt expression mit allen Typen etc. frei                   */
  731. {
  732.     if(!p) return;
  733.     if(p->flags==ASSIGNADD){
  734.         if(!p->right){ierror(0);return;}
  735.         if(p->right->left==p->left)  p->left=0;
  736.         if(p->right->right==p->left) p->left=0;
  737.     }
  738.     if(p->flags==CALL&&p->alist) free_alist(p->alist);
  739.     if(p->ntyp) freetyp(p->ntyp);
  740.     if(p->left) free_expression(p->left);
  741.     if(p->right) free_expression(p->right);
  742.     free(p);
  743. }
  744.  
  745.